package demo7;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;


class MyComparator implements Comparator<Student> {
    @Override
    public int compare(Student o1, Student o2) {
//        return o1.getName().compareTo(o2.getName());
        return o1.getAge() - o2.getAge();
    }
}
class Money implements Cloneable {
    public int m;
    public Money(int m) {
        this.m = m;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
class Student implements Cloneable{
    private String name;
    private int age;
    public Student(String name,int age) {
            this.name = name;
            this.age = age;
    }

    Money m = new Money(25);
    public String getName() {
            return name;
    }

    public void setName(String name) {
            this.name = name;
    }

    public int getAge() {
            return age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public void setAge(int age) {
            this.age = age;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Student tmp = (Student) super.clone();
        tmp.m = (Money) this.m.clone();
        return tmp;
    }

}

abstract class i {
    public i() {}

}
class i1 extends i {

}

//class Student implements Comparable<Student> {
//    private String name;
//    private int age;
//    public Student(String name,int age) {
//        this.name = name;
//        this.age = age;
//    }
//
//    public String getName() {
//        return name;
//    }
//
//    public void setName(String name) {
//        this.name = name;
//    }
//
//    public int getAge() {
//        return age;
//    }
//
//    public void setAge(int age) {
//        this.age = age;
//    }
//
//    @Override
//    public int compareTo(Student o) {
//        return this.name.compareTo(o.name);
//    }
//}
public class test2 {
    public static void main(String[] args) throws CloneNotSupportedException {
        Student student = new Student("hehe", 12);
        Student student1 = (Student) student.clone();
        System.out.println(student1);
    }
    public static void main2(String[] args) {
        Integer i1 = new Integer(1);
        Integer i2 = new Integer(2);
        swap(i1,i2);
        System.out.println(i1);
    }

    private static void swap(Integer x,Integer y) {
        int x1 = x.intValue();
        int y1 = y.intValue();
        int tmp = x1;
        x1 = y1;
        y1 = tmp;
    }

    public static void main1(String[] args) {
        Student[] students = new Student[3];
        students[0] = new Student("hheh",20);
        students[1] = new Student("hhaha",8);
        students[2] = new Student("heij",50);

        char[] arr = new char[]{'a','b'};
        String name = new String(arr);

        MyComparator myComparator = new MyComparator();
        Arrays.sort(students,myComparator);
        System.out.println(Arrays.toString(students));
    }
}
